package net.tp.algo.bit;

/**
 *
 * @author Trung Phan
 *
 */
public class BitManipulation {


    public static int parity(int number) {
        int parity = 0;
        while (number > 0) {
            number &= (number - 1); // remove the lowest set bit.
            parity ^= 1;
        }
        return parity;
    }

    public static void main(String ... args) {

        int n = 0b11011110;
        System.out.println(Integer.toBinaryString(n & (n-1)));
        System.out.println(Integer.toBinaryString(n & ~(n-1)));
        System.out.println(Integer.toBinaryString(n & (n+ (1<<3))));
        System.out.println(Integer.toBinaryString(n & (n+ ~(1<<3))));

    }


}
